package com.zx.idc.backend.gui.slog;


import com.baomidou.mybatisplus.plugins.Page;
import com.zx.idc.backend.gui.common.BasicBaseApi;
import com.zx.idc.backend.gui.common.Result;
import com.zx.idc.backend.gui.common.base.BaseExcelApi;
import com.zx.idc.backend.gui.slog.service.SlogHotIpInterfaceService;
import com.zx.idc.common.exception.FTPUploadFailedException;
import com.zx.idc.common.lang.tuple.Tuple2;
import com.zx.idc.common.lang.tuple.Tuple3;
import com.zx.idc.ds.slog.entity.SlogHotIp;
import com.zx.idc.ds.slog.service.ISlogHotIpService;
import com.zx.idc.ds.slog.vo.SlogHotIpVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 活跃ip地址信息表 前端控制器
 * </p>
 *
 * @author chendong
 * @since 2019-03-26
 */
@RestController
@RequestMapping("/api/slogHotIp")
public class SlogHotIpController extends BasicBaseApi<ISlogHotIpService, SlogHotIp> implements BaseExcelApi<ISlogHotIpService, SlogHotIpVo> {
    @Autowired
    private SlogHotIpInterfaceService slogHotIpInterfaceService;

    @GetMapping("/query-page")
    @RequiresPermissions("regulatory-log:slog-hot-ip")
    public Result<Page<SlogHotIpVo>> page(Page<SlogHotIpVo> page, SlogHotIpVo slogHotIpVo) {
        return success(service.pageByParam(page, slogHotIpVo));
    }

    @GetMapping("/list")
    @RequiresPermissions("regulatory-log:slog-hot-ip")
    public Result<List<SlogHotIpVo>> list(SlogHotIpVo slogHotIpVo) {
        return success(service.listByParam(slogHotIpVo));
    }

    @PostMapping("/report")
    @RequiresPermissions("regulatory-log:slog-hot-ip:edit")
    public Result<Boolean> report(@RequestBody List<SlogHotIp> dataList) {
        String msg;
        try {
            return success(slogHotIpInterfaceService.reportData(dataList));
        } catch (FTPUploadFailedException e) {
            log.error(e.getMessage(), e);
            msg = e.getMessage();
        }
        return error(msg);
    }

    @PostMapping("/handle")
    @RequiresPermissions("regulatory-log:slog-hot-ip:edit")
    public Result<Boolean> deal(@RequestBody Tuple3<List<SlogHotIp>, Integer, String> tuple) {
        return success(service.updateDeal(tuple.getV1(), tuple.getV2(), tuple.getV3()));
    }

    @PostMapping("/cancel-handle")
    @RequiresPermissions("regulatory-log:slog-hot-ip:edit")
    public Result<Boolean> cancelDeal(@RequestBody List<SlogHotIp> slogHotIpList) {
        return success(service.updateCancelDeal(slogHotIpList));
    }
}

